ceTe Software Help Library for Java August - 2020
DynamicPDF Merger for Java / Programming with Merger for Java / Working With AcroForms / Marking Form Fields as Read Only
In This Topic
    Marking Form Fields as Read Only
    In This Topic

    This example shows how to mark form fields as read only so that they cannot be modified once they are set.

    [Java]
        MergeDocument document = new MergeDocument("[PhysicalPath]/MyDocument.pdf");
    // Set the field values
    document.getForm().getFields().getFormField("TextBox1").setValue("My Text"); // TextBox field
    // Make the form read only
    document.getForm().setReadOnly(true);
    document.draw("[PhysicalPath]/MyDocument.pdf");

    Marking form fields as read only does not prevent the PDF from being modified (through a PDF viewer) so that the read only property is turned off and then the form field content can be modified again. Adding encryption to the PDF document (see example below) after the form fields have been set to read only will prevent users of the PDF from being able to modify the form fields.

    The example code below demonstrate how to add a read-only property to all PDF fields as well as lock the PDF down from being edited:

    [Java]
        MergeDocument document = new MergeDocument("[PhysicalPath]/MyDocument.pdf");
    document.getForm().setReadOnly(true);
    RC4128Security security = new RC4128Security("owner", "user");
    security.setAllowFormFilling(false);
    security.setAllowUpdateAnnotsAndFields(false);
    security.setAllowEdit(false);
    document.setSecurity(security);
    document.draw("[PhysicalPath]/MyDocument1.pdf");